import os
import shutil

def copy_source_folders(properties_file, target_dir):
    # 读取并解析配置文件
    directories = []
    with open(properties_file, 'r') as f:
        for line in f:
            line = line.strip()
            if not line or '=' not in line:
                continue
            _, value = line.split('=', 1)
            dirs = [d.strip() for d in value.split(',')]
            directories.extend(dirs)
    
    # 创建目标目录
    os.makedirs(target_dir, exist_ok=True)
    
    # 遍历所有源目录
    for src_dir in directories:
        if not os.path.isdir(src_dir):
            print(f"警告：目录 '{src_dir}' 不存在，已跳过")
            continue
        
        # 递归复制文件
        for root, dirs, files in os.walk(src_dir):
            for file in files:
                src_path = os.path.join(root, file)
                rel_path = os.path.relpath(src_path, src_dir)
                dest_path = os.path.join(target_dir, rel_path)
                
                os.makedirs(os.path.dirname(dest_path), exist_ok=True)
                shutil.copy2(src_path, dest_path)
                print(f"已复制: {src_path} -> {dest_path}")

if __name__ == "__main__":
    copy_source_folders(
        properties_file="nativeSourceFolders.properties",
        target_dir="bin/library"
    )